package mil.af.amc.adpetracker.web.actions.struts1.Manufacturer;

import mil.af.amc.adpetracker.web.actions.struts1.AbstractDispatchAction;
import mil.af.amc.adpetracker.service.ManufacturerService;
import org.apache.struts.action.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Please Fill in this Javadoc
 *
 * @author TSgt Jason Ferguson
 */

public class ManufacturerDispatchAction extends AbstractDispatchAction {

    private ManufacturerService manufacturerService;

    public void setManufacturerService(ManufacturerService manufacturerService) {
        this.manufacturerService = manufacturerService;
    }

    public ActionForward viewManufacturerIndex(ActionMapping actionMapping,
                                            ActionForm actionForm,
                                            HttpServletRequest httpServletRequest,
                                            HttpServletResponse httpServletResponse) {

        return actionMapping.findForward("viewManufacturerIndex");

    }

    public ActionForward viewCreateManufacturer(ActionMapping actionMapping,
                                            ActionForm actionForm,
                                            HttpServletRequest httpServletRequest,
                                            HttpServletResponse httpServletResponse) {

        return actionMapping.findForward("viewCreateManufacturer");

    }

    public ActionForward createManufacturer(ActionMapping actionMapping,
                                            ActionForm actionForm,
                                            HttpServletRequest httpServletRequest,
                                            HttpServletResponse httpServletResponse) {

        DynaActionForm form = (DynaActionForm) actionForm;

        ActionMessages errors = form.validate(actionMapping, httpServletRequest);
        if (!errors.isEmpty()) {
            saveErrors(httpServletRequest, errors);
            actionMapping.findForward("viewCreateManufacturer");
        }

        manufacturerService.createManufacturer(form.getMap());

        return actionMapping.findForward("viewManufacturerIndex");

    }
}
